const { dbInit } = require('./lib/dbinit');
const config = require('./config/config');
const MysqlSession = require('koa-mysql-session');

global._root = __dirname;
global._logger = require('./lib/logger');
global.config = config;

module.exports = () => {
  // 初始化db
  dbInit(config.mysql);

  try {
    // 配置存储session信息的mysql
    global.sessionStore = new MysqlSession({
      ...config.mysql,
      acquireTimeout: 100000,
    });
  } catch (err) {
    _logger.info('sessionStore prepare fail', err);
  }
};
